//
//  HMOAuthViewController.swift
//  Weibo
//
//  Created by teacher on 2017/6/5.
//  Copyright © 2017年 teacher. All rights reserved.
//

import UIKit

//  唯一应用id
let AppKey = "1627533550"
//  授权回调地址，用于拼接授权码
let Redirect_Uri = "http://www.itcast.cn"

//  第三方登录界面
class HMOAuthViewController: UIViewController {

    //  MARK:   --懒加载控件
    private lazy var webView: UIWebView = UIWebView()
    
    //  重写load，自定义视图
    override func loadView() {
        view = webView
    }
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        requestOAuthLogin()
        setupNavUI()
    }
    
    //  加载第三方登录界面
    private func requestOAuthLogin() {
        //  请求登录地址
        let urlStr = "https://api.weibo.com/oauth2/authorize?client_id=\(AppKey)&redirect_uri=\(Redirect_Uri)"
        let urlRequest = URLRequest(url: URL(string: urlStr)!)
        webView.loadRequest(urlRequest)
    }
    
    //  设置导航栏按钮
    private func setupNavUI() {
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "取消", target: self, action: #selector(cancelAction))
        navigationItem.title = "微博登录"
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "自动填充", target: self, action: #selector(autoFillAction))
    }
    
    //  MARK:   -- 取消按钮点击事件
    @objc private func cancelAction() {
        self.dismiss(animated: true, completion: nil)
    }

    //  MARK:   -- 自动填充按钮点击事件
    @objc private func autoFillAction() {
    
        print("自动填充")
    }
 

}
